<template>
  <nav>
    <div @click="goToCity">{{ cityname }}</div>
    <ul>
      <li
        v-for="(item, index) in list"
        :key="item.url"
        :class="{ active: index === active }"
        @click="liclick(index, item.url)"
      >
        {{ item.title }}
      </li>
    </ul>
    <span class="iconfont icon-ai219"></span>
  </nav>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      // list: ["热映", "影院", "待映", "经典电影"],
      list: [
        {
          title: "热映",
          url: "/hot",
        },
        {
          title: "影院",
          url: "/cinema",
        },
        {
          title: "待映",
          url: "/wait",
        },
        {
          title: "经典电影",
          url: "/classic",
        },
      ],
      active: 0,
    };
  },
  computed: mapState({
    cityname: (state) => state.city.cityname,
  }),
  // computed: {
  //   cityname() {
  //     // 当我们去获取state的数据的时候，分了模块，state后面加上模块名
  //     return this.$store.state.city.cityname;
  //   },
  // },
  methods: {
    liclick(i, url) {
      this.active = i;
      this.$router.push("/home/movie" + url);
    },
    goToCity() {
      // 编程式导航
      this.$router.push("/city");
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../../assets/css/var.less";
nav {
  width: 100%;
  height: 44px;
  border-bottom: 1px solid @border-color;
  background: #fff;
  display: flex;
  justify-content: space-between;
  font-size: @m-font;

  div {
    width: 80px;
    height: 100%;
    .center();
  }

  ul {
    flex: 1;
    display: flex;
    justify-content: space-around;
    align-items: center;

    .active {
      font-weight: 900;
      position: relative;

      &::after {
        content: "";
        width: 20px;
        height: 4px;
        border-radius: 2px;
        background: @theme-color;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        bottom: -9px;
      }
    }
  }

  span {
    width: 40px;
    height: 100%;
    .center();
    color: @theme-color;
    font-size: @xl-font;
  }
}
</style>
